package com.xcenter.cabinet.file.dao;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

import com.xcenter.cabinet.model.FileModel;

public class FileDaoProvider {

	public String batchInsert(Map<?, ?> map) {
		@SuppressWarnings("unchecked")
		List<FileModel> list = (List<FileModel>) map.get("list");
		StringBuffer sb = new StringBuffer();
		sb.append("INSERT INTO cabinet_file ");
		sb.append("VALUES ");
		MessageFormat mf = new MessageFormat(buildParam());
		for (int i = 0; i < list.size(); i++) {
			sb.append(mf.format(new Object[] { i }));
			if (i < list.size() - 1) {
				sb.append(",");
			}
		}
		return sb.toString();
	}

	private String buildParam() {
		StringBuffer sb = new StringBuffer();
		sb.append("(")
			.append("#'{'list[{0}].id}" + ",")
			.append("#'{'list[{0}].filename}" + ",")
			.append("#'{'list[{0}].folderPath}" + ",")
			.append("#'{'list[{0}].size}" + ",")
			.append("#'{'list[{0}].uploadDate}" + ",")
			.append("#'{'list[{0}].md5}" + ",")
			.append("#'{'list[{0}].origFilename}")
			.append(")");
			
		return sb.toString();

	}

}
